perf(runtime): enable webpack compress and mangle#5057
Open
perf(runtime): enable webpack compress and mangle#5057
Conversation
Enable Terser compression and mangling for the jsii runtime bundle. This reduces bundle size and improves require() time at startup. - compress: true — enables dead code elimination and constant folding - mangle: true — shortens local variable names - keep_classnames: true — preserves class names used in error messages (serialization.ts:1296, objects.ts:131) and stack traces - keep_fnames: true — preserves function names for readable stack traces sent to language runtimes via the jsii protocol - Both keep_* options set at terserOptions top level AND inside mangle to protect against both compress and mangle passes Estimated 10-50ms faster initial require() due to smaller bundle size.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enable Terser compression and mangling for the jsii runtime webpack bundle, reducing bundle size and improving startup time.
Changes
packages/@jsii/runtime/webpack.config.js:compress: false→compress: true(dead code elimination, constant folding)beautify: true→ removed (no need for pretty output)mangle: false→mangle: { keep_classnames: true, keep_fnames: true }keep_classnamesandkeep_fnamesto protect against compress pass renamingSafety Analysis
keep_classnames: true: Preserves class names used inconstructor.nameerror messages (serialization.ts:1296,objects.ts:131) andKernel.prototypeaccess (recording.ts:34)keep_fnames: true: Preserves function names in stack traces sent to language runtimes viaerror.stackin the jsii protocol (host.ts:204)terserOptionstop level (protects compress pass) AND insidemangle(protects mangle pass)eval(),with,new Function(),arguments.calleein the codebaseconst enumsafe:JsiiErrorTypevalues are inlined as string literals by TypeScript before Terser sees themdevtool: 'source-map'unchanged,.mapfiles ship with all language runtimesBlast Radius
This bundle is embedded in ALL four language runtimes (Python, Java, .NET, Go). Full cross-language compliance testing is recommended before merge.
Test plan
constructor.namevalues in error messages